package logic

import (
	"context"
	"errors"
	"fmt"
	"gorm.io/gorm"
	"strconv"
	"user_srv/model/mysql"

	"user_srv/internal/svc"
	"user_srv/user"

	"github.com/zeromicro/go-zero/core/logx"
)

type FindRealNameLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewFindRealNameLogic(ctx context.Context, svcCtx *svc.ServiceContext) *FindRealNameLogic {
	return &FindRealNameLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

func (l *FindRealNameLogic) FindRealName(in *user.FindRealNameInfoRequest) (*user.FindRealNameInfoResponse, error) {
	// todo: 查询实名信息

	u := mysql.RealName{}

	fmt.Println("接收的id为", in.UserId)

	err := u.GetUserRealNameByUserIdOrIdCard(strconv.FormatInt(in.UserId, 10), in.IdCared)
	if err != nil && !errors.Is(err, gorm.ErrRecordNotFound) {
		logx.Error("未查询到身份信息", err)
		return nil, err
	}
	status := false
	if u.ID > 0 {
		status = true
	}
	return &user.FindRealNameInfoResponse{Secc: status}, nil
}
